package com.douyang.service.impl;

import com.douyang.model.OrderStatementLog;
import com.douyang.service.OrderStatementLogService;
import com.douyang.service.SaveLogService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;

@Service("payNotify")
public class SavePayNotifyServiceImpl implements SaveLogService {
    @Autowired
    OrderStatementLogService orderStatementLogService;


    @Override
    public Object saveLog(ProceedingJoinPoint joinPoint) throws Throwable {
        Map<String,String> arg = (Map<String, String>) joinPoint.getArgs()[0];
        OrderStatementLog orderStatementLog=new OrderStatementLog();
        orderStatementLog.setOps("支付宝回调："+arg.toString());
        orderStatementLog.setCreateTime(LocalDateTime.now());
        if(arg.containsKey("out_trade_no")){orderStatementLog.setOrderStatementId(Long.valueOf((arg.get("out_trade_no"))));}
        Object proceed = joinPoint.proceed();
        orderStatementLog.setResult((String) proceed);
        orderStatementLog.setSuccess(true);
        orderStatementLogService.save(orderStatementLog);
        return proceed;
    }
}
